import java.io.*;

public class ProcessJad
{
	public static void main(String[] args)
	{
		String inFileName = null;
		String outFileName = null;
		int i, j;

		String key = null;
		String value = null;
		for (i = 0; i < args.length; i++)
		{
			try
			{
				j = args[i].indexOf("=");
				if (j != -1)
				{
					key = args[i].substring(0,j).toLowerCase();
					value = args[i].substring(j + 1);

					if (key.equals("in")) inFileName = value;
					if (key.equals("out")) outFileName = value;
				}
			}
			catch(Exception ex){}
		}

		System.out.print("Post-processing JAD file '" + inFileName + "'...");

		try
		{
			FileInputStream in = new FileInputStream(inFileName);
			PrintStream out = new PrintStream(new FileOutputStream(outFileName));

			char c;
			StringBuffer sb = new StringBuffer();
			String res;

			while((i = in.read()) != -1)
			{
				c = (char)i;
				if (c == '^') c = '&';

				if (c == '\n' || (c == '\r'))
				{                                                
					res = sb.toString().trim();
					if (res.length() > 0 && (!res.startsWith("//")))
					{
						out.println(res);
					}
					sb.setLength(0);
				}
				else sb.append(c);
			}
			in.close();
			out.close();
			System.out.println("OK");
		}
		catch(Exception ex)
		{
			System.out.println("failed:");
			ex.printStackTrace();
		}
	}
}